Skip to content

Conversation

s1gr1d
Copy link
Member

@s1gr1d s1gr1d commented Mar 31, 2025

Add "Frontend" and "Backend" to quickly see the runtime.

image

image

part of #85732

@s1gr1d s1gr1d self-assigned this Mar 31, 2025
@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Mar 31, 2025
@s1gr1d s1gr1d changed the title feat(issue-details): Add runtime label for Meta-Frameworks feat(issue-details): Add runtime label for JS issues Apr 4, 2025
@s1gr1d s1gr1d force-pushed the sig/runtime-label branch from 571ee2b to 021ad3f Compare April 4, 2025 14:16
@s1gr1d s1gr1d requested review from scttcper, leeandher and mydea April 4, 2025 14:16
@s1gr1d s1gr1d marked this pull request as ready for review April 4, 2025 14:16
@s1gr1d s1gr1d requested a review from a team as a code owner April 4, 2025 14:16
Copy link
Member

@scttcper scttcper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While i do think this solves a problem for nextjs etc. I'm not sure it makes sense for sentry.javascript.cloudflare or even our own frontend project. Should we check the project platform?

It also maybe needs a tooltip? the word "Frontend" by itself is maybe not the most clear

Copy link

codecov bot commented Apr 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #88312      +/-   ##
==========================================
+ Coverage   87.70%   87.71%   +0.01%     
==========================================
  Files       10143    10063      -80     
  Lines      573197   568665    -4532     
  Branches    22518    22353     -165     
==========================================
- Hits       502729   498817    -3912     
+ Misses      70036    69452     -584     
+ Partials      432      396      -36     


if (
(event.contexts.runtime && !event.contexts.browser) ||
event.contexts?.cloud_resource // Cloudflare, Vercel etc.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
event.contexts?.cloud_resource // Cloudflare, Vercel etc.
event.contexts.cloud_resource // Cloudflare, Vercel etc.

only one optional chaining here, I guess either everywhere or nowhere?

}

if (
(event.contexts.runtime && !event.contexts.browser) ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that backend events also get a browser context, sadly...? I believe this is extracted from the user agent of the incoming request.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually not, but I can exclude the browser check here 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can just check for if (event.contexts.runtime) { // this is backend } - this should be true for all current JS SDKs, I think:

  1. For bun: runtime: { name: 'bun', version: Bun.version },
  2. For cloudflare: runtime: { name: 'cloudflare' },
  3. For deno: runtime: { name: 'deno', version: Deno.version.deno },
  4. For node: runtime: { name: 'node', version: global.process.version },
  5. For vercel-edge: runtime: { name: 'vercel-edge' },

We do not set this for any other SDKs, as far as I can tell.
Obviously this is not super robust, but should be good for the time being I guess..? We could additionally also check for contexts.cloud_resource I suppose!

alternatively we could also allow-list the values of runtime.name:

if (['node', 'bun', 'deno', 'cloudflare', 'vercel-edge'].includes(contexts.runtime?.name)) {
  // backend
}

but then we need a robust check for browser too 🤔 In the future, we could check on contexts.page which would be robust as this would be frontend-only. Today, we can only do weird heuristics I guess - e.g. contexts.browser + !contexts.runtime, for example...?

*/
export function getRuntimeLabelAndTooltip(
event: Event,
knownRuntimeType?: {isBackend?: boolean; isFrontend?: boolean}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a bit of a weird API, what if you pass { isBackend: true, isFrontend: true }? I'd rather make this an enum:

knownRuntimeType?: 'frontend' | 'backend'

Comment on lines 196 to 198
(event.contexts.runtime?.name &&
['node', 'bun', 'deno', 'cloudflare', 'vercel-edge'].includes(
event.contexts.runtime.name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can simplify this to:

Suggested change
(event.contexts.runtime?.name &&
['node', 'bun', 'deno', 'cloudflare', 'vercel-edge'].includes(
event.contexts.runtime.name
(['node', 'bun', 'deno', 'cloudflare', 'vercel-edge'].includes(
event.contexts.runtime?.name || ''

or something like this, I believe?

event.contexts.runtime.name
))
) {
return {label: t('Backend'), tooltip: t('Error from Server, Edge or Worker Runtime')};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, can we be more specific here - based on the runtime name? :D So if it is node / bun / deno, "Error from Server", if it is cloudflare "Error from Worker Runtime" if it is vercel-edge "Error from Edge", or something like this?

Thinking about this, maybe we can/should just remove the knownRuntimeType escape hatch and use this always, this would be kind of neat I guess... But no strong feelings!

@s1gr1d s1gr1d merged commit f48b6cc into master Apr 14, 2025
41 checks passed
@s1gr1d s1gr1d deleted the sig/runtime-label branch April 14, 2025 15:14
@github-actions github-actions bot locked and limited conversation to collaborators Apr 30, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Frontend Automatically applied to PRs that change frontend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants